package cn.com.hp.feature.service.impl;

import cn.com.hp.feature.domain.dto.CommunityAndMenuParamDTO;
import cn.com.hp.feature.domain.dto.CommunityInfoDTO;
import cn.com.hp.feature.domain.entity.CommunityInfo;
import cn.com.hp.feature.domain.entity.MenuInfo;
import cn.com.hp.feature.domain.vo.CommunityMenuVO;
import cn.com.hp.feature.domain.vo.PageVO;
import cn.com.hp.feature.mapper.CommunityInfoMapper;
import cn.com.hp.feature.mapper.MenuInfoMapper;
import cn.com.hp.feature.service.ICommunityInfoService;
import cn.com.hp.feature.service.IMenuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: hjz
 * @since: 2022/8/29
 * @description:
 */
@Service
public class CommunityInfoServiceImpl extends ServiceImpl<CommunityInfoMapper, CommunityInfo> implements ICommunityInfoService {
    @Autowired
    private CommunityInfoMapper communityInfoMapper;

    @Override
    public List<CommunityInfo> selectCommunityList(CommunityInfo communityInfo) {
        return communityInfoMapper.selectCommunityList(communityInfo);
    }

    @Override
    public PageVO<CommunityInfo> selectCommunityPageByRequest(CommunityInfoDTO communityInfoDTO) {
        PageVO<CommunityInfo> data = new PageVO();

        //默认分页数据是第一页，每页10条
        int current = communityInfoDTO.getPage() == null ? 1 : communityInfoDTO.getPage();
        int size = communityInfoDTO.getRow() == null ? 10 : communityInfoDTO.getRow();
        Page<CommunityInfo> page = new Page<>(current, size);
        //获取分页数据
        Page<CommunityInfo> pages = communityInfoMapper.selectCommunityPageByRequest(page, communityInfoDTO);
        data.setList(pages.getRecords());
        data.setPage(pages.getCurrent());
        data.setPageSize(pages.getSize());
        data.setTotal(pages.getTotal());
        return data;
    }

    @Override
    public List<CommunityMenuVO> communityAndMenulist(CommunityAndMenuParamDTO param) {

        return communityInfoMapper.communityAndMenulist(param);

    }

    @Override
    public PageVO<CommunityMenuVO> selectCommunityAndMenuPage(CommunityAndMenuParamDTO param) {
        PageVO<CommunityMenuVO> data = new PageVO();

        //默认分页数据是第一页，每页10条
        int current = param.getPage() == null ? 1 : param.getPage();
        int size = param.getRow() == null ? 10 : param.getRow();
        Page<CommunityMenuVO> page = new Page<>(current, size);
        //获取分页数据
        Page<CommunityMenuVO> pages = communityInfoMapper.selectCommunityAndMenuPage(page, param);
        data.setList(pages.getRecords());
        data.setPage(pages.getCurrent());
        data.setPageSize(pages.getSize());
        data.setTotal(pages.getTotal());
        return data;
    }
}
